<?php
/* 
 *收货
 */
class ReceiveAction extends TransAction {
    public function _filter(&$map) {
        $key = trim($_REQUEST['keywords']);
        if(!empty($key)) {
            $map['name'] = array('like',"%".$key."%");//产品名称
            $map['enter_no'] = array('like',"%".$key."%");
            $map['tm'] = array('like',"%".$key."%");//条码
            $map['_logic'] = "or";
        }
        $sid = $_REQUEST['supplier_id'];
        if(!empty($sid))
            $map['supplier_id'] = $sid;
        $map['finish'] = 0; //未入库结束的
    }

    public function index()
    {
        parent::index('Buy');
    }

    public function _before_edit() {
        parent::_before_edit();
        $enter_details = M('Buy_detail')->alias('e')->
                            join(C('DB_PREFIX').'Product p on e.product_id = p.id')->
                            where('buy_id = '.$_GET['id'] )->field('e.*,product_id,p.name,p.tm,p.unit_id')->findAll();
        $this->assign('enter_details',$enter_details); 
    }

    public function edit()
    {
        $this->assign('vo',M('Buy')->where('id ='.$_POST['id'])->find());
        $this->display();
    }
    
    public function foreverdelete($field='name') {
        A('Buy')->foreverdelete($field);
    }
}
?>
